package com.qfedu.video.service.impl;

import com.qfedu.video.entry.Course;
import com.qfedu.video.entry.CourseExample;
import com.qfedu.video.mapper.CourseMapper;
import com.qfedu.video.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yanzhenwei
 * @date 2021-07-14 10:43
 */
@Service
public class CourseServiceImpl implements CourseService {

    @Autowired
    CourseMapper courseMapper;

    public List<Course> getAllList() {

        CourseExample courseExample = new CourseExample();
        return courseMapper.selectByExample(courseExample);

    }

    public List<Course> getListByCondition() {
        CourseExample courseExample = new CourseExample();
        CourseExample.Criteria criteria = courseExample.createCriteria();
        //criteria.andCourseTitleEqualTo("UI基础入门");
        // select * from course where course_title like "%UI%"
        criteria.andCourseTitleLike("%UI%");
        return courseMapper.selectByExample(courseExample);
    }

    public void insertCourse(Course course) {
        courseMapper.insert(course);
    }

    public List<Course> getCourseBySubjectId(int subjectId) {

        CourseExample courseExample = new CourseExample();
        CourseExample.Criteria criteria = courseExample.createCriteria();
        criteria.andSubjectIdEqualTo(subjectId);
        return courseMapper.selectByExampleWithBLOBs(courseExample);

    }

    public Course getCourseById(int courseId) {
        return courseMapper.selectByPrimaryKey(courseId);
    }
}
